using System.Web.Mvc;
using System.Web.Routing;
using Dgg.Anug.Cqrs.Core.Infrastructure.Web;
using Dgg.Anug.Cqrs.Core.Presentation.Controllers;
using MvcContrib.Routing;
using StructureMap;

namespace Dgg.Anug.Cqrs.Core.Infrastructure.Bootstrapping
{
	public class ApplicationBootstrapper
	{
		public ApplicationBootstrapper RegisterRoutes(RouteCollection routes)
		{
			routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
			routes.IgnoreRoute("favicon.ico");

			MvcRoute.MappUrl("{controller}/{action}/{id}")
				.ToDefaultAction<HomeController>(c => c.Index())
				.WithDefaults(new { id = string.Empty })
				.AddWithName("Default", routes);

			return this;
		}

		public ApplicationBootstrapper ConfigureIoC()
		{
			ObjectFactory.Configure(configuration =>
				configuration.Scan(scanner =>
				{
					scanner.TheCallingAssembly();
					scanner.LookForRegistries();
				}));
			ControllerBuilder.Current.SetControllerFactory(typeof(CustomControllerFactory));
			return this;
		}
	}
}